package com.moneytalks.blazepoc.services {
	import mx.messaging.ChannelSet;
	import mx.messaging.channels.AMFChannel;
	import mx.rpc.AbstractService;
	import mx.rpc.remoting.RemoteObject;
	
	public class ServiceLocator {
		
		private static var _instance:ServiceLocator;
		private static var _created:Boolean; // Abstract class work arround
		private static var _services:Array = [];
		public function ServiceLocator() {
			if (!_created) throw new Error("Singleton class");
		}
		public static function getInstance():ServiceLocator {
			if (null == _instance) {
				_created = true;
				_instance = new ServiceLocator();
				_created = false;
			}
			return _instance;
		}
		public function registerService(serviceName:String, service:AbstractService):void {
			if (!isRegistered(serviceName)) {
				_services[serviceName] = service;
			}
		}
		public function retrieveRemoteObject(serviceName:String):RemoteObject {
			return _services[serviceName] as RemoteObject;
		}
		private function isRegistered(key:String):Boolean {
			for (var i:int=0; i < _services.length; i++) {
				if (null != _services[key]) return true;
			}
			return false;
		}
	}
}